from pyecharts.charts import *
from pyecharts import options as opts


def line_plot_sample(all_data):
    row = all_data.row_values(0)[1:]
    col = all_data.col_values(0)[1:]
    line = Line()
    line.add_xaxis(row)
    for mid in range(1, all_data.nrows):
        row_data = all_data.row_values(mid)
        line.add_yaxis(row_data[0], row_data[1:])
    line.set_global_opts(title_opts=opts.TitleOpts(title=all_data.name), toolbox_opts=opts.ToolboxOpts())
    line.render('11.html')


def line_plot(all_data):
    line = (
        Line(init_opts=opts.InitOpts(theme="dark", width="800px", height="450px"))
            .set_global_opts(
            title_opts=opts.TitleOpts(title=all_data.name),
            tooltip_opts=opts.TooltipOpts(trigger="axis"),
            toolbox_opts=opts.ToolboxOpts(is_show=True),
            xaxis_opts=opts.AxisOpts(type_="category", boundary_gap=False),
        )
    )
    line.add_xaxis(all_data.row_values(0)[1:])
    for i in range(1, all_data.nrows):
        line.add_yaxis(
            series_name=all_data.row_values(i)[0],
            y_axis=all_data.row_values(i)[1:],
            markpoint_opts=opts.MarkPointOpts(
                data=[
                    opts.MarkPointItem(name="最大值", type_="max"),
                    opts.MarkPointItem(name="最小值", type_="min"),
                ]
            ),
            markline_opts=opts.MarkLineOpts(
                data=[opts.MarkLineItem(type_="average", name="平均值"),
                      opts.MarkLineItem(symbol="none", x="90%", y="max"),
                      ]
            )
        )
    line.render("temperature_change_line_chart.html")
